package com.woniu.cms.finance.core.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.cms.finance.core.entity.FinanceGathering;
import com.woniu.cms.finance.core.service.IFinanceAccountingService;
import com.woniu.cms.finance.core.service.IFinanceGatheringService;
import com.woniu.cms.finance.core.service.IFinanceInvoiceIncomeService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 收款表 前端控制器
 * </p>
 *
 * @author kiron
 * @since 2022-09-20
 */
@RestController
@RequestMapping("/finance-gathering")
@Api(tags ="收款表")
public class FinanceGatheringController {
    @Autowired
    private IFinanceGatheringService financeGatheringService;
    @GetMapping("list")
    @ApiOperation("获取项目列表")
    public Result getList(){
       Result result= financeGatheringService.getList();
       return result;
    }
    @PostMapping("add")
    @ApiOperation("新增收款单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gatheringList", value = "添加收款记录集合")
    })
    public Result addGathering(@RequestBody List<FinanceGathering> gatheringList){
       Result result = financeGatheringService.addGathering(gatheringList);
       return result;
    }

    @PutMapping("updateStatus")
    @ApiOperation("提交收款单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "gatheringList", value = "添加收款记录集合")
    })
    public Result updateStatus(@RequestBody List<FinanceGathering> gatheringList){
        for (FinanceGathering financeGathering : gatheringList) {
            financeGathering.setStatus(1);
            boolean b = financeGatheringService.updateById(financeGathering);
            if(b){
                return Result.ok("提交成功");
            }
            return Result.error("提交失败");
        }
        return Result.error("提交失败");
    }
    @GetMapping("getAll")
    @ApiOperation("收款单列表视图")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "页面大小"),
    })
    public Result getAll(Integer currentPage, Integer pageSize){
        Result result = financeGatheringService.getAll(currentPage,pageSize);
        return result;
    }
}

